#! /usr/bin/env python
#coding=utf-8

from django import template
from django.contrib.admin.views.main import AdminBoundField

register = template.Library()

@register.simple_tag
def number_of_videos(bound_field_sets):
    bound_field_set = bound_field_sets[0]
    value = bound_field_set.bound_field_lines[0]
    
    if isinstance(value, AdminBoundField):
        bound_fields = [value]
    else:
        bound_fields = [bf for bf in value]
    
    if bound_fields[0].original:
        return 'Number of videos %d'%(bound_fields[0].original.video_set.count(), )
    else:
        return ''
